package com.rtp2p.rtcoresdkdemo.add.ap

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.viewModels
import com.rtp2p.rtcoresdkdemo.R
import com.rtp2p.rtcoresdkdemo.add.AddViewModel
import com.rtp2p.rtcoresdkdemo.base.BaseFragment
import com.rtp2p.rtcoresdkdemo.databinding.AddBindingApFragmentBinding

class AddBindingApFragment : BaseFragment() {
    private val addViewModel: AddViewModel by viewModels({ requireActivity() })
    private val viewModel: AddBindingApViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel.init(requireContext(), addViewModel.wifiSsid, addViewModel.wifiPwd) {
            requireActivity().finish()
        }
    }

    override fun initWorkspaceAction(inflater: LayoutInflater, container: ViewGroup?): View {
        val binding = DataBindingUtil.inflate<AddBindingApFragmentBinding>(
            inflater,
            R.layout.add_binding_ap_fragment,
            container,
            false
        )
        binding.lifecycleOwner = viewLifecycleOwner
        binding.vm = viewModel

        binding.btnReturn.setOnClickListener { finish() }
        return binding.root
    }

    override fun onStart() {
        super.onStart()
        viewModel.onStart()
    }

    override fun onStop() {
        super.onStop()
        viewModel.onStop()
    }
}